cd "C:\Users\au544415\Desktop\BJPS"

use "C:\Users\au544415\Desktop\BJPS\study1_before.dta", clear
keep durationinseconds ageres candemmg support correctatte task resp country genderr dissumm partymmain canarmy cancrime canedu canabort canss canimmi canwel canunion cantax matexsoc matexredi urbanr partisan edurr 
gen attitude = (matexsoc + matexredi)/2
recode urbanr (1 2 = 0) (3 = 1), gen(metro)
recode edurr (1 2 = 0) (3 = 1), gen(highedu)
gen study = "study 1"
gen countryyear = 1 if country == "US"
replace countryyear = 2 if country == "UK"
replace countryyear = 3 if country == "SK"
replace countryyear = 4 if country == "MX"
replace countryyear = 5 if country == "CZ"
rename candemmg undemocratic
rename ageres age
rename support vote
rename correctatte attentive
recode genderr (2 = 0 "Male") (1=1 "Female") (else=.), gen(female)
recode vote (1 = 0) (2 = 0.25) (3 = 0.5) (4 = 0.75) (5 = 1)
generate distance = ((dissumm-1)/(7-1))*1
drop dissumm
generate PID = ((partymmain-1)/(5-1))*1
save study1.dta, replace

use "C:\Users\au544415\Desktop\BJPS\study2_before.dta", clear
keep durationinseconds ageres candemmg vote governor task resp round genderr edurr dissumm partymatch cansoc canredi matexsoc matexredi PIDres_1 
gen partisan = 1 if PIDres_1 == "Democrat"
replace partisan = 1 if PIDres_1 == "Republican"
replace partisan = 1 if PIDres_1 == "Other"
replace partisan = 0 if PIDres_1 == "Independent"
recode edurr (1 2 = 0) (3 4 5 6 7 = 1), gen(highedu)
gen attitude = (matexsoc + matexredi)/2
gen study = "study 2"
encode study, gen(studynum)
gen countryyear = 13 if round == 2
replace countryyear = 14 if round == 3
drop if round == 1 //no voting intentions outcome in this round
rename candemmg undemocratic
rename ageres age
rename vote vote1
rename resp res
encode governor, gen(attention)
recode attention (1 3 4 5 6 7 = 0 "Inattentive") (2 = 1 "Attentive"), gen(attentive)
drop governor attention
recode genderr (2 = 0 "Male") (1=1 "Female") (else=.), gen(female)
gen resp = res + 79000
generate vote = ((vote1-1)/(7-1))*1
generate distance = ((dissumm-1)/(7-1))*1
drop dissumm
generate PID = ((partymatch-1)/(7-1))*1
save study2.dta, replace

use "C:\Users\au544415\Desktop\BJPS\study3_before.dta", clear
keep durationinseconds Undempla fmccorrect country q5 candidate q4 metro highedu partisan
gen study = "study 3"
encode study, gen(studynum)
encode country, gen(countrynum)
gen task = 1
gen countryyear = 6 if country == "United States"
replace countryyear = 7 if country == "Mexico"
replace countryyear = 8 if country == "India"
replace countryyear = 9 if country == "Italy"
replace countryyear = 10 if country == "Poland"
replace countryyear = 11 if country == "Brazil"
replace countryyear = 12 if country == "South Africa"
rename fmccorrect attentive
encode q4, gen(genderres)
recode genderres (2 3 4 5 7 = 1 "Female") (8 9 10 18 = 0 "Male") (else=.), gen(female)
rename Undempla undemocratic
rename candidate vote
gen resp = _n+60000
recode vote (1 = 0) (2 = 0.25) (3 = 0.5) (4 = 0.75) (5 = 1)
destring q5, generate(age) force
save study3.dta, replace


use "C:\Users\au544415\Desktop\BJPS\study4_before.dta", clear
keep durationinseconds ageres candemmg fc task resp fmc genderr dissumm partymatch canabort canss canimmi canwel canunion cantax urbanr edurr matexredi matexsoc PIDres_1 
gen partisan = 1 if PIDres_1 == "Democrat"
replace partisan = 1 if PIDres_1 == "Republican"
replace partisan = 1 if PIDres_1 == "Other"
replace partisan = 0 if PIDres_1 == "Independent"
gen study = "study 4"
encode study, gen(studynum)
gen attitude = (matexsoc + matexredi)/2
recode urbanr (1 2 = 0) (3 = 1), gen(metro)
recode edurr (1 2 = 0) (3 = 1), gen(highedu)
gen countryyear = 17
rename candemmg undemocratic
rename fc vote
recode genderr (2 = 0 "Male") (1=1 "Female") (else=.), gen(female)
recode fmc (1 2 3 4 5 7 = 0 "Inattentive") (6 = 1 "Attentive"), gen(attentive)
drop fmc
destring ageres, generate(age) force
generate distance = ((dissumm-1)/(7-1))*1
drop dissumm
generate PID = ((partymatch-1)/(7-1))*1
save study4.dta, replace

use "C:\Users\au544415\Desktop\BJPS\study5_2_before.dta", clear
gen version = 2
rename resp res
gen resp = res + 111000
save study5_2_before_indicator.dta, replace
use "C:\Users\au544415\Desktop\BJPS\study5_1_before.dta", clear
gen version = 1
rename resp res
gen resp = res + 125000
append using study5_2_before_indicator.dta
drop if party == "Liberal Democrats"
keep durationinseconds q5 attentive behavior ub votefor task resp copartisanship q6 q4 version leftright_1 q3
gen study = "study 5"
encode study, gen(studynum)
destring leftright_1, gen(attitude1)
generate attitude = ((attitude1-0)/(10-0))*(5-1)+1
encode q6, gen(edurr)
recode edurr (1 = 0) (2 = 0) (3 = 1), gen(highedu)
gen countryyear = 15 if version == 1
replace countryyear = 16 if version == 2
rename ub undemocratic
encode q3, gen(metro1)
recode metro1 (1 = 0) (2=1) (3=0), gen(metro)
encode q4, gen(genderr)
recode genderr (2 = 0 "Male") (1=1 "Female") (else=.), gen(female)
destring q5, generate(age) force
rename votefor vote
rename copartisanship PID
save study5.dta, replace


**Graham & Svolik (2020)
import delimited "C:\Users\au544415\Desktop\BJPS\data_experiment.csv", bindquote(strict) varnames(1) encoding(ISO-8859-2) stringcols(63) numericcols(1 2 3 4 5 6 9 10 11 12 13 14 15 16 18 20 21 22 23 24 26 28 29 30 31 32 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 61 62 64 65 66 67 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 86 87 88 89 90 91 92 93 95 97 98 99 100 101 103 105 106 107 108 109 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 138 139 141 142 143 144 146 147 148 149 150 151 152 153 154 155 156 157 158 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 221 222 223 224 225 226 230 237 242 254 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 310 311 312 313 314 315 316 317 318 319 320 321 322 323 7 8 36 60 62 84 86 87 113 159 160 177 218 219 220 232 324) clear 

gen undemocratic = .
replace undemocratic = 0 if c_dem_type == "g"
replace undemocratic = 1 if c_dem_type == "u"
label define Undemocratic 0 "Democratic" 1 "Undemocratic"
label values undemocratic Undemocratic
rename c_win vote
rename id resp
keep undemocratic vote resp age
gen study = "gs20"
encode study, gen(studynum)
save graham_svolik2020.dta, replace

*****Carey et al (2020)
import spss using "C:\Users\au544415\Desktop\BJPS\MICH0033_B_output.sav", clear
gen careyversion = 1
save carey1.dta, replace
use "C:\Users\au544415\Desktop\BJPS\MICH0038_B_output.dta", clear
gen careyversion = 2
append using carey1.dta


***Reshaping
rename cand1_elect elect_1
rename cand2_elect elect_2
rename cand3_elect elect_3
rename cand4_elect elect_4
rename cand5_elect elect_5
rename cand6_elect elect_6
rename cand7_elect elect_7
rename cand8_elect elect_8
rename cand9_elect elect_9
rename cand10_elect elect_10
rename cand11_elect elect_11
rename cand12_elect elect_12
rename cand13_elect elect_13
rename cand14_elect elect_14
rename cand15_elect elect_15
rename cand16_elect elect_16
rename cand17_elect elect_17
rename cand18_elect elect_18
rename cand19_elect elect_19
rename cand20_elect elect_20
rename cand1_invest invest_1
rename cand2_invest invest_2
rename cand3_invest invest_3
rename cand4_invest invest_4
rename cand5_invest invest_5
rename cand6_invest invest_6
rename cand7_invest invest_7
rename cand8_invest invest_8
rename cand9_invest invest_9
rename cand10_invest invest_10
rename cand11_invest invest_11
rename cand12_invest invest_12
rename cand13_invest invest_13
rename cand14_invest invest_14
rename cand15_invest invest_15
rename cand16_invest invest_16
rename cand17_invest invest_17
rename cand18_invest invest_18
rename cand19_invest invest_19
rename cand20_invest invest_20
rename cand1_comp comp_1
rename cand2_comp comp_2
rename cand3_comp comp_3
rename cand4_comp comp_4
rename cand5_comp comp_5
rename cand6_comp comp_6
rename cand7_comp comp_7
rename cand8_comp comp_8
rename cand9_comp comp_9
rename cand10_comp comp_10
rename cand11_comp comp_11
rename cand12_comp comp_12
rename cand13_comp comp_13
rename cand14_comp comp_14
rename cand15_comp comp_15
rename cand16_comp comp_16
rename cand17_comp comp_17
rename cand18_comp comp_18
rename cand19_comp comp_19
rename cand20_comp comp_20
rename cand1_courts courts_1
rename cand2_courts courts_2
rename cand3_courts courts_3
rename cand4_courts courts_4
rename cand5_courts courts_5
rename cand6_courts courts_6
rename cand7_courts courts_7
rename cand8_courts courts_8
rename cand9_courts courts_9
rename cand10_courts courts_10
rename cand11_courts courts_11
rename cand12_courts courts_12
rename cand13_courts courts_13
rename cand14_courts courts_14
rename cand15_courts courts_15
rename cand16_courts courts_16
rename cand17_courts courts_17
rename cand18_courts courts_18
rename cand19_courts courts_19
rename cand20_courts courts_20


gen vote_1 = 1 if conjoint1 == 1
replace vote_1 = 0 if conjoint1 == 2
recode vote_1 (1 = 0) (0 = 1), gen(vote_2)
gen vote_3 = 1 if conjoint2 == 1
replace vote_3 = 0 if conjoint2 == 2
recode vote_3 (1 = 0) (0 = 1), gen(vote_4)
gen vote_5 = 1 if conjoint3 == 1
replace vote_5 = 0 if conjoint3 == 2
recode vote_5 (1 = 0) (0 = 1), gen(vote_6)
gen vote_7 = 1 if conjoint4 == 1
replace vote_7 = 0 if conjoint4 == 2
recode vote_7 (1 = 0) (0 = 1), gen(vote_8)
gen vote_9 = 1 if conjoint5 == 1
replace vote_9 = 0 if conjoint5 == 2
recode vote_9 (1 = 0) (0 = 1), gen(vote_10)
gen vote_11 = 1 if conjoint6 == 1
replace vote_11 = 0 if conjoint6 == 2
recode vote_11 (1 = 0) (0 = 1), gen(vote_12)
gen vote_13 = 1 if conjoint7 == 1
replace vote_13 = 0 if conjoint7 == 2
recode vote_13 (1 = 0) (0 = 1), gen(vote_14)
gen vote_15 = 1 if conjoint8 == 1
replace vote_15 = 0 if conjoint8 == 2
recode vote_15 (1 = 0) (0 = 1), gen(vote_16)
gen vote_17 = 1 if conjoint9 == 1
replace vote_17 = 0 if conjoint9 == 2
recode vote_17 (1 = 0) (0 = 1), gen(vote_18)
gen vote_19 = 1 if conjoint10 == 1
replace vote_19 = 0 if conjoint10 == 2
recode vote_19 (1 = 0) (0 = 1), gen(vote_20)

drop *reg

reshape long elect invest comp courts vote, i(caseid) j(cand, string)

gen undemocratic1 = elect + invest + comp + courts
generate undemocratic = ((undemocratic1-4)/(8-4))*1
rename caseid resp
keep undemocratic vote resp age careyversion
gen study = "careyetal20"
encode study, gen(studynum)
drop careyversion
save careyetal2020.dta, replace


*****Saikkonen & Christensen (2022)
use "C:\Users\au544415\Desktop\BJPS\Replication data Lure of populism.dta", clear
gen age = (18+29)/2 if ageclass == "18-29"
replace age = (30+39)/2 if ageclass == "30-39"
replace age = (40+49)/2 if ageclass == "40-49"
replace age = (50+59)/2 if ageclass == "50-59"
replace age = (60+69)/2 if ageclass == "60-69"
rename choice vote
gen resp = respid + 4000
gen study = "saik_chris22"
encode study, gen(studynum)
recode attjudic (2 = 1 "Undemocratic") (1 = 0 "Democratic"), gen(judic)
recode attviol (3 = 1 "Undemocratic") (2 = 0.5) (1 = 0 "Democratic"), gen(viol)
gen undemocratic = (judic+viol)/2
keep age undemocratic vote resp study vote
save saik_chris2022.dta, replace

*Reuter & Szakonyi
use "C:\Users\au544415\Desktop\BJPS\rs2016.dta", clear
recode exp_turnout (5 = 1) (4 = 0.75) (3 = 0.5) (2 = 0.25) (1 = 0), gen(vote)
rename exp_votefor votealt
rename any_fraud undemocratic
gen study = "rs2016"
gen resp = _n+2000000000
drop if age > 200
keep vote undemocratic age study votealt resp
save "C:\Users\au544415\Desktop\BJPS\reuterszakonyi2016_final.dta", replace

*Aarslew
use "C:\Users\au544415\Desktop\BJPS\replication_data_aarslew.dta", clear
alpha support legitimacy compliance pei, gen(index)
gen vote = index/10
rename treatment undemocratic
gen study = "aarslew22"
gen resp = _n+20000000000
keep vote undemocratic age study resp
save "C:\Users\au544415\Desktop\BJPS\aarslew22.dta", replace

*Krishnarajan
use "C:\Users\au544415\Desktop\BJPS\krishnarajan.dta", clear
recode profile_age (1 = 26) (2 = 44.5) (3 = 65), gen(age)
recode dem (1 = 0) (2 = 0.25) (3 = 0.5) (4 = 0.75) (5 = 1), gen(vote)
recode treat (1 2 = 0) (3 4 = 1), gen(undemocratic)
gen resp = respondent_id + 900000
gen study = "krishnarajan23"
keep vote undemocratic age resp study
save "C:\Users\au544415\Desktop\BJPS\krishnarajan23.dta", replace

*Mares & Visconti
use "C:\Users\au544415\Desktop\BJPS\conjoint_Romania.dta", clear
gen vote = 1 if selected == 1 & candidate == 1
replace vote = 1 if selected == 2 & candidate == 2
replace vote = 0 if selected == 1 & candidate == 2
replace vote = 0 if selected == 2 & candidate == 1
recode atmita (1 = 0) (2 3 = 1)
recode atinti (1 = 0) (2 = 1)
gen undemocratic = (atinti + atmita)/2
gen resp = idnum + 9000000
gen study = "mv2021"
keep undemocratic age resp vote study
save maresvisconti, replace

*Lewandowski & Jankowski
use "C:\Users\au544415\Desktop\BJPS\lewanjan.dta", clear
rename selected vote
gen vote1 = 1-vote
gen vote2 = vote-vote1
encode ResponseId, gen(resp1)
gen resp = resp1 + 10000000
gen study = "lj22"
keep vote resp age study vote2
save lewandowskijankowski, replace

*Append and save final dataset
append using study5.dta study1.dta study3.dta study2.dta careyetal2020.dta graham_svolik2020.dta study4.dta saik_chris2022.dta maresvisconti.dta krishnarajan23.dta aarslew22.dta reuterszakonyi2016_final.dta
label define countryyear 1 "Study 1, US" 2 "Study 1, UK"  3 "Study 1, South Korea" 4 "Study 1, Mexico"  5 "Study 1, Czech R." 6 "Study 3, US" 7 "Study 3, Mexico"  8 "Study 3, India" 9 "Study 3, Italy" 10 "Study 3, Poland" 11 "Study 3, Brazil"  12 "Study 3, South Africa" 13 "Study 2, US (1)" 14 "Study 2, US (2)" 15 "Study 5, UK (1)" 16 "Study 5, UK (2)"  17 "Study 4, US"
label values countryyear countryyear
encode study, gen(studyi)
gen redistribution = .
replace redistribution = cantax //stance on tax
replace redistribution = canunion if redistribution == . //stance on unions
replace redistribution = canwel if redistribution == . //stance on welfare spending
replace redistribution = canedu if redistribution == . //stance on universal education
replace redistribution = 1 if canredi == 4 | canredi == 5 | canredi == 6
replace redistribution = 0 if canredi == 1 | canredi == 2 | canredi == 3
gen social = .
replace social = canss //stance on same sex marriage
replace social = canabort if social == . //stance on abortion
replace social = canimmi if social == . //stance on immigration
replace social = 1 if cansoc == 1 | cansoc == 3 | cansoc == 4
replace social = 0 if cansoc == 2 | cansoc == 4 | cansoc == 6
recode redistribution (0 = 1) (1 = 0) (.75 = .25) (.25 = .75), gen(antiega)
recode social (0 = 1) (1 = 0) (.5 = .5) (.75 = .25) (.25 = .75), gen(antimino)
replace task = 1 if study == "study 3"
destring durationinseconds, gen(duration)
gen minutes = duration/60
drop vote1 q4 q5 q6 version genderr partymmain genderres round res partymatch duration q3 leftright_1 attitude1 behavior metro1 cantax canunion canwel canimmi canss canabort matexredi matexsoc canedu cancrime canarmy PIDres_1 canredi cansoc ageres
save finaldata.dta, replace
drop if countryyear == . //excluding additional studies for data for external robustness test
save externalvalidity.dta, replace